﻿//  --------------------------------
//  Copyright (c) 2010 Michael Schuler, Sascha Burger. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://p2pmessaging.codeplex.com/license
//  ---------------------------------
using System;
using System.Collections.Generic;
using NUnit.Framework;
using p2pMessaging.BL.Model;
using p2pMessaging.Contracts;
using p2pMessaging.Interfaces;

namespace p2pMessaging.Tests
{
	[TestFixture]
	public class EmailMessageServiceTest
	{
		private IMessageService myMessageService;

		[SetUp]
		public void SetUp()
		{
			myMessageService = ServiceLocator.Get<IMessageService>("Email");
		}
		
		[TearDown]
		public void TearDown()
		{
			myMessageService.Dispose();
		}
		
		[Test]
		[ExpectedException(ExceptionType = typeof(ArgumentNullException))]
		public void SendNull()
		{
			myMessageService.Send(null);
		}
		
		[Test]
		public void Send()
		{
			Message msg = new Message();
			msg.Data = "data";
			msg.Recipient.Add(new Contact { EmailAddress = "sascha.burger@afg.ch" });
			msg.Sender = new Contact { EmailAddress = "p2ptest@michaelschuler.ch" };
			msg.Subject = "title";

			Assert.AreNotEqual(0, msg.GetHashCode());
			Assert.IsFalse(msg.Equals(null));
			Assert.IsFalse(msg.Equals(new Message()));
			
			myMessageService.Send(msg);
			
			Assert.AreEqual(myMessageService.PluginId, msg.PluginId);
		}
		
		[Test]
		public void Receive()
		{
			List<IMessage> messages = myMessageService.Receive();
			Assert.IsEmpty(messages);
		}
		
		[Test]
		public void GetGuid()
		{
			Assert.AreNotEqual(Guid.Empty, myMessageService.PluginId);
		}
	}
}
